export function getTimeStatus(startTime = new Date(), endTime) {
  if (!endTime) {
    return {
      state: 1,
      text: ''
    }
  }
  const start = new Date()
  const end = new Date(endTime)

  // 时间差（毫秒）
  const diffMs = end - start
  const dayMs = 1000 * 60 * 60 * 24

  // 格式化天数（带 0.5 进位）
  const formatDays = (ms) => {
    const days = ms / dayMs
    if (days <= 0) return 0
    const intPart = Math.floor(days)
    const decimal = days - intPart

    if (decimal === 0) {
      return intPart
    } else if (decimal <= 0.5) {
      return intPart + 0.5
    } else {
      return intPart + 1
    }
  }

  if (diffMs > 0) {
    // 未过期
    const remainDays = formatDays(diffMs)
    if (remainDays > 3) {
      return {
        state: 'primary',
        className: 'primary_text',
        text: `${remainDays}天`
      }
    } else {
      return {
        state: 'warning',
        className: 'warning_text',
        text: `${remainDays}後天到期`
      }
    }
  } else {
    // 已过期
    const overDays = formatDays(Math.abs(diffMs))
    return {
      state: 'danger',
      className: 'danger_text',
      text: `超期${overDays}天`
    }
  }
}
